<template>
  <a-card :bordered="false">
    <super-query
      :fieldList="tableObj.columns"
      @query="handlerquery"
    />
    <v-table
      bordered
      ref="table"
      :data="loadData"
      :columns="tableObj.columns"
    >
      <template v-slot:buttons>
        <a-button icon="plus" @click="addData" type="primary" v-action="'sys:post:save'">新建</a-button>
      </template>
      <span slot="name" slot-scope="{row,text}">
        <a @click="showData(row)">{{ text }}</a>
      </span>
      <span slot="isSystem" slot-scope="{row,text}">
        <span v-if="text === 'Y'">是</span>
        <span v-else>否</span>
      </span>
      <span slot="action" slot-scope="{row,text}">
        <span>
          <a href="javascript:;" @click="edit(row)">编辑</a>
        </span>
      </span>
    </v-table>
    <post-form
      @ok="queryPage"
      ref="modalForm"
    />
  </a-card>

</template>
<script>
import { tableObj } from './post'
import { TableMixin } from '@/mixins/TableMixin'
import { fetchList, delObj } from '@/api/sys/post'
import PostForm from './form'
export default {
  name: 'Index',
  mixins: [TableMixin],
  components: {
    PostForm
  },
  data () {
    return {
      tableObj,
      queryParam: {},
      loadData: parameter => {
        return fetchList(
          Object.assign(parameter, this.queryParam)
        ).then(res => {
          return res.data
        })
      }
    }
  },
  methods: {
    handlerquery (e) {
      this.queryParam = { ...e }
      this.queryPage()
    },
    edit (record) {
      this.$refs.modalForm.init(record.id, 'edit')
    },
    addData () {
      this.$refs.modalForm.init('', 'add')
    },
    showData (record) {
      this.$refs.modalForm.init(record.id, 'show')
    }
  }
}
</script>

<style scoped>

</style>
